package org.example.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.catalina.User;
import org.example.domain.model.Result;
import org.example.mapper.UserMapper;
import org.example.service.IUserService;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements IUserService {

    private UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public Result findPageUser(Integer page, Integer limit) {
        Page<User> p = PageHelper.startPage(page, limit);
        userMapper.selectList(Wrappers.emptyWrapper());

        Map<String, Object> data = new HashMap<>();
        data.put("total", p.getTotal());
        data.put("users", p.getResult());

        return Result.buildSuccess(data);
    }
}
